package com.ost.kautilya.modeling;

import java.io.Serializable;

public class ReportAttribute implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private final int type;
	private final int index;
	private final AttributeInfo fi;
	public static final int ATTRIBUTE = 1;
	public static final int CLASS_ATTRIBUTE = 0;

	public AttributeInfo getAttributeInfo() {
		return fi;
	}

	public ReportAttribute(int type, int rptIndex, AttributeInfo info) {
		this.type = type;
		this.index = rptIndex;
		this.fi = info;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ReportAttribute) return fi.equals(((ReportAttribute) obj).fi);
		else if (obj instanceof AttributeInfo) return fi.equals(obj);
		else return false;
	}

	@Override
	public int hashCode() {
		return fi.hashCode();
	}

	public String getResultingName() {
		return "F" + index;
	}

	public String getMetaName() {
		return fi.getAttributeName();
	}

	public String getDataType() {
		if (fi.getAttributeDataType().equalsIgnoreCase("text")) {
			return "VARCHAR(32672)";
		} else if (fi.getAttributeDataType().equalsIgnoreCase("date")) {
			return "DATE";
		} else {
			return "REAL";
		}
	}
}
